<?php

namespace App\Http\Controllers\Admin\hwtc;

use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\CommonController;
use App\Models\hwtc\Log;
use DB;


class LogController extends CommonController
{

    public function __construct()
    {
        parent::__construct();
        view()->share([
            '_log' => 'active',
//            'cartypes'=>Cartype::get()

        ]);
    }

    public function index(Request $request)
    {


        //查找
        $where = function ($query) use ($request) {
            if ($request->has('keyword') and $request->keyword != '') {
                $search = "%" . $request->keyword . "%";
                $query->where('url', 'like', $search)->orWhere('post_data','like',$search);
            }

        };

        $logs=Log::where($where)->orderBy('logtime','desc')->paginate(config('hwtc.page_size'));

        return view('admin.hwtc.url.index')->with('logs',$logs);
    }




    //删除
    public function destroy($id)
    {

        Log::destroy($id);
        return redirect(route('hwtc.log.index'))->with('success','删除成功~');
    }
    //多选删除
    public function destroy_checked(Request $request)
    {
        $ids=$request->input("checked_id"); //$ids是个数组
        Log::destroy($ids);
    }

    //vmcu download
    public function vmcudownload(Request $request){
//        return $request->id;

//        $vmcu=Vmcu::where('id',$request->id)->first();
        $vmcu=Vmcu::find($request->id);
//        return $vmcu;
        if(!$vmcu){
            return '文件不存在！';
        }
        $path=getcwd().$vmcu->url;
        down_file($path);
    }

    
}
